﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace ecdl.demo.model.word {
    public class WordTaskCatalog : ITaskProvider{

        private static readonly string DEFAULT_XML = "ecdl.demo.model.word.res.WordTasksCatalog.xml";

        private static System.IO.Stream OpenDefaultFile() {
            System.IO.Stream stream = typeof(WordTaskCatalog).Assembly.GetManifestResourceStream(DEFAULT_XML);
            return stream;
        }

        public static WordTaskCatalog GetDefaultCatalogue() {
            WordTasksSerializer serializer = new WordTasksSerializer();

            var questionaire = (WordTaskCatalog)serializer.Deserialize(new StreamReader(OpenDefaultFile()));
            return questionaire;
        }

        public WordTaskCatalog() {
            Tasks = new List<WordTaskDTO>();
        }
        [XmlElement("WordTask")]
        public List<WordTaskDTO> Tasks { get; set; }



        public IEnumerable<ITask> GetTasks(persistence.ModelFactory modelFactory) {

            var tasks = new List<WordTask>();
            foreach (var item in Tasks) {
                tasks.Add((WordTask)item.ToModel(modelFactory));
            }
            return tasks;
        }
    }
}
